package com.example.pry.recyclerview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import java.util.ArrayList;
import java.util.List;

public class RecyclerViewActivity extends AppCompatActivity {

    private List<Imagetext> imagetextList=new ArrayList<> ( );

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.recyclerview_layout );

        init();

        android.support.v7.widget.RecyclerView recyclerView= findViewById(R.id.recycle_view);
        LinearLayoutManager layoutManager=new LinearLayoutManager(this);
        //横向列表
        //layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        //网格布局的列表
        //GridLayoutManager layoutManager=new GridLayoutManager ( this,3 );
        //分割线设置
        recyclerView.addItemDecoration(new DividerItemDecoration(this,
                DividerItemDecoration.VERTICAL));

        recyclerView.setLayoutManager(layoutManager);
        RecyclerViewAdapter adapter=new RecyclerViewAdapter(imagetextList);
        recyclerView.setAdapter (adapter);
    }

    private void init(){
        for(int i=0;i<5;i++) {
            Imagetext a = new Imagetext ( "aaa", R.mipmap.ic_launcher );
            imagetextList.add ( a );
            Imagetext b = new Imagetext ( "bbb", R.mipmap.ic_launcher );
            imagetextList.add ( b );
            Imagetext c = new Imagetext ( "ccc", R.mipmap.ic_launcher );
            imagetextList.add ( c );
            Imagetext d = new Imagetext ( "ddd", R.mipmap.ic_launcher );
            imagetextList.add ( d );
            Imagetext e = new Imagetext ( "eee", R.mipmap.ic_launcher );
            imagetextList.add ( e );
            Imagetext f = new Imagetext ( "fff", R.mipmap.ic_launcher );
            imagetextList.add ( f );
        }
    }
}

